const useListeningUploadSource = (initInfo, uploadSourceRef, initFolder, showFolderAddDialog) => {
  // 显示上传资源弹窗
  const showUploadSourceDialog = item => {
    initInfo.value.isUploadDialogShow = true
    uploadSourceRef.value.showDialog(item)
    if (initInfo.value.isChooseResource) {
      uploadSourceRef.value.isChooseResource()
    }
  }

  // 显示上传资源弹窗 （上传到当前文件夹）
  const uploadCurrentFolder = () => {
    if (initInfo.value.isRecycle) {
      showUploadSourceDialog(null)
    } else {
      showUploadSourceDialog(initInfo.value.breadcrumbList[initInfo.value.breadcrumbList.length - 1])
    }
  }

  // 上传资源后，更新数据
  const updateFolder = v => {
    console.log(v, '上传的最新资源')
    // 存储新上传的内容
    const urlList: any = []
    if (v && v.length > 0) {
      v.forEach(item => {
        urlList.push(item.url)
      })
    }
    initInfo.value.newUploadList = urlList

    initFolder()
  }

  // 显示新建文件夹弹窗 （上传文件弹窗内的新建文件夹按钮点击）
  const uploadSourceShowFolderAdd = v => {
    showFolderAddDialog(v)
  }

  // 上传资源弹窗关闭后，将上传资源弹窗的显示隐藏状态改变
  const uploadDialogClose = () => {
    initInfo.value.isUploadDialogShow = false
    initInfo.value.rightClickFolder = null
  }

  return {
    showUploadSourceDialog,
    uploadCurrentFolder,
    updateFolder,
    uploadSourceShowFolderAdd,
    uploadDialogClose
  }
}
export default useListeningUploadSource
